#ifndef N1DATE_H_2009_09_26
#define N1DATE_H_2009_09_26

#include "N1Lib.h"
#include <time.h>

typedef double N1TimeInterval; //in seconds
typedef double N1AbsoluteTime; //seconds from 1601-01-01 00:00:00

class N1Date : public N1Object  {
protected:
    struct tm  m_time;

public:
    N1Date();
    N1Date(uint16 year, uint16 month, uint16 day, uint16 hour, uint16 min, uint16 sec);
    virtual ~N1Date() { };

    N1NAME_DECL;

    static N1Date* today();
    static N1Date* dateWithAbsoluteTime(N1AbsoluteTime t);
    static N1Date* dateWithTimeIntervalSinceNow(N1TimeInterval secs);

    static bool   isLeapYear( uint32 y ) { return !(y%400) || (!(y%4) && y%100); };
    static uint16 calculateDayOfYear(uint16 year, uint16 month, uint16 day);
    static uint16 calculateDayOfWeek(uint16 year, uint16 month, uint16 day);

    uint16 yearOfCommonEra() const ;
    uint16 monthOfYear() const ;  /* 0..11, 0-January  */
    uint16 dayOfMonth() const ;   /* 1..31  */
    uint16 dayOfWeek() const ;    /* 0..6, 0-Sunday  */
    uint16 dayOfYear() const ;
    uint16 hourOfDay() const ;
    uint16 minuteOfHour() const ;
    uint16 secondOfMinute() const ;

    N1AbsoluteTime absoluteTime() const ;

    bool operator<(const N1Date& date) const ;
};

#endif //N1DATE_H_2009_09_26
